package com.cedarhd.finance.msg.controller.api;

import com.cedarhd.finance.msg.common.JsonResult;
import com.cedarhd.finance.msg.common.ProcessAPI;
import com.cedarhd.finance.msg.common.enums.PointType;
import com.cedarhd.finance.msg.controller.Routes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Evan
 * @date 2018/3/27
 */
@Api(value = "类型管理", description = "类型管理")
@RestController
public class EnumController {
    @ApiOperation(value = "埋点类型", notes = "埋点类型", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(value = Routes.TYPE_POINT, method = RequestMethod.GET)
    public JsonResult pointType(HttpServletRequest request) {
        ProcessAPI api = (result, validate) -> {
            List<Map<String,String>> pointTypes = new ArrayList<>();
            for(PointType type : PointType.values()){
                Map<String,String> item = new HashMap<>(2);
                item.put("name",type.name());
                item.put("value",type.getDescription());
                pointTypes.add(item);
            }

            result.setResult(pointTypes);
            result.setSize(Long.valueOf(pointTypes.size()));

        };
        return api.process(request);

    }

}
